# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=dendrite
pkgver=0.13.5
pkgrel=0
pkgdesc="Second-generation Matrix homeserver written in Go"
url="https://github.com/matrix-org/dendrite"
license="Apache-2.0"
arch="all"
makedepends="
	go
	olm-dev
	sqlite-dev
	"
subpackages="$pkgname-openrc"
pkgusers="$pkgname"
pkggroups="$pkgname"
install="$pkgname.pre-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/matrix-org/dendrite/archive/refs/tags/v$pkgver.tar.gz
	dendrite.initd
	dendrite.confd
	"
options="net" # required to download go modules

export GOFLAGS="$GOFLAGS -tags=libsqlite3"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	for cmd in dendrite generate-keys create-account; do
		go build -trimpath -v -o bin/$cmd ./cmd/$cmd
	done
}

check() {
	DENDRITE_TEST_SKIP_NODB=1 go test ./...
}

package() {
	install -Dm755 bin/dendrite "$pkgdir"/usr/bin/dendrite
	install -Dm755 bin/generate-keys "$pkgdir"/usr/bin/dendrite-generate-keys
	install -Dm755 bin/create-account "$pkgdir"/usr/bin/dendrite-create-account

	install -Dm644 dendrite-sample.yaml "$pkgdir"/etc/$pkgname/dendrite.yaml
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
59b37b087d7fc711281eb86af0ca0ea12a0ba21b87a838cc6cc8925ff4ea5fd1a30eb1fe012db8fd1fd969f3512a81c76e829cdb45fe3f57b97c321e70ea65d1  dendrite-0.13.5.tar.gz
5d228aa3970a176e10e24dc5cd8611103c944de660a65cc1e6221ae65a804b1bfbe0a6465716ccda37c4d82670d0ff27f017c44c382ab9eb25b7bc6e037d01b0  dendrite.initd
a6a088683a6aebc431d3eb289bd0d4dbaede698d1a5da25d6af2aad79e9cd36db02ce9173ab6904249f23b88bca5d1630258736feef7e8266e6c22220d74fa1f  dendrite.confd
"
